package com.Cychat.post.mapper;


import com.Cychat.commons.entity.pojo.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Auther: 崔航
 * @Date: 2025/10/28:14:24
 * @Description:
 */
@Mapper
public interface PostMapper extends BaseMapper<Post> {
    @Select("SELECT * FROM post p JOIN user u ON p.user_id = u.user_id " +
            "WHERE p.status != 0 " +
            "ORDER BY " +
            "CASE WHEN p.status = 2 THEN 0 ELSE 1 END, " +
            "p.create_time DESC")
    public List<Post> getAllPosts(Page<Post> page);

    @Select("SELECT * FROM post p JOIN user u ON p.user_id = u.user_id WHERE post_id = #{postId}")
    public Post getPostById(Integer postId);
    @Select("SELECT * FROM post p JOIN user u ON p.user_id = u.user_id WHERE p.user_id = #{userId} ORDER BY CASE WHEN p.status = 2 THEN 0 ELSE 1 END, " +
            "p.create_time DESC")
    List<Post> getPostByUserId(Long userId);
    @Update("UPDATE post SET like_count = like_count + 1, update_time = NOW() WHERE post_id = #{postId}")
    int increaseLikeCount(@Param("postId") Integer postId);

    @Select("SELECT * FROM post p JOIN user u ON p.user_id = u.user_id " +
            "WHERE p.status != 0 " +
            "ORDER BY " +
            "CASE WHEN p.status = 2 THEN 0 ELSE 1 END, " +
            "p.create_time DESC")
    public List<Post> getPost();
}
